﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Assets.Scripts
{
    public class Image
    {
        public Sprite ImageTexture { get; set; }
        public Direction ImageDirection { get; set; }
        public ImageBackgroundColor ImageBackgroundColor { get; set; }

        public Image() { }

        public Image(Sprite image, Direction direction, ImageBackgroundColor color)
        {
            this.ImageTexture = image;
            this.ImageDirection = direction;
            this.ImageBackgroundColor = color;
        }
    }

   public class ImageFactory
    {
              
       private List<Image> factoryTextures = new List<Image>();
       private System.Random rnd;

       public void CreateImagesFactory(Image image)
       {
           factoryTextures.Add(image);
       }

       public void CreateImagesFactory(IEnumerable<Image> images)
       {
           foreach (var image in images)
               factoryTextures.Add(image);
       }

       public Image GetRandomImage(Direction direction, ImageBackgroundColor color)
       {
         var result = factoryTextures
              .Where(x => x.ImageDirection == direction && x.ImageBackgroundColor == color)
              .ToList();
         return result[(new System.Random()).Next(0, result.Count)];
       }

       public void CreateFromResources()
       {
           var sprites = Resources.LoadAll<Sprite>("Sprites/");
           foreach(var sprite in sprites)
           {
               var infoSprite = Resources.Load(string.Format("SpritesInfo/{0}.txt",sprite.name)).ToString().Trim().Split('$');
               factoryTextures.Add(new Image(sprite, (Direction)Enum.Parse(typeof(Direction), infoSprite[0]), (ImageBackgroundColor)Enum.Parse(typeof(ImageBackgroundColor), infoSprite[1])));
           }
           
       }
       
    }

    public enum Direction
    {
        Up,
        Down
    }

    public enum ImageBackgroundColor
    {
        Red,
        Green
    }
}
